package com.wang.jmonkey.modules.region.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.wang.jmonkey.modules.region.model.dto.RegionInOutParamDTO;
import com.wang.jmonkey.modules.region.model.entity.RegionInOut;
import com.wang.jmonkey.modules.region.mapper.RegionInOutMapper;
import com.wang.jmonkey.modules.region.service.IRegionInOutService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 入区登记表 服务实现类
 * </p>
 *
 * @author tianchao
 * @since 2020-04-27
 */
@Service
public class RegionInOutServiceImpl extends ServiceImpl<RegionInOutMapper, RegionInOut> implements IRegionInOutService {

    @Autowired
    private RegionInOutMapper regionInOutMapper;

    /**
     * 添加预约信息
     *
     * @param entity
     * @return
     */
    @Override
    public Boolean savePro(RegionInOut entity) {
        entity.setStatus(1);
        regionInOutMapper.insert(entity);
        return true;
    }

    /**
     * 根据RegionInOutParamDTO 查询分页信息
     *
     *
     * @param param {startDate endDate}
     * @return
     */
    @Override
    public Page<RegionInOut> selectPageByCondition( RegionInOutParamDTO param) {
        int current = param.getCurrent(),size = param.getSize();
        List<RegionInOut> list = regionInOutMapper.selectPageByCondition(param,current,size);
        long total = regionInOutMapper.countPageByCondition(param);
        Page<RegionInOut> result = new Page<>();
        result
                .setRecords(list)
                .setTotal(total)
                .setCurrent(current)
                .setSize(size);
        return result;
    }
}
